1 package uba.db.column.io;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.ByteArrayOutputStream;
5 import java.io.DataInputStream;
6 import java.io.DataOutputStream;
7
8 import junit.framework.TestCase;
9 import uba.db.column.CharColumnSpecification;
10
11 /***
12 * @version $Revision: 1.1 $
13 */
14 public class CharColumnReaderTest extends TestCase {
15 private CharColumnReader reader;
16 private ByteArrayInputStream input;
17
18 /***
19 * @see junit.framework.TestCase#setUp()
20 */
21 protected void setUp() throws Exception {
22 ByteArrayOutputStream out = new ByteArrayOutputStream();
23 CharColumnSpecification specification = new CharColumnSpecification("prueba", 10);
24 CharColumnWriter writer = (CharColumnWriter) specification
25 .writerFor(new DataOutputStream(out));
26 writer.write("abc");
27 writer.write("hola");
28
29 input = new ByteArrayInputStream(out.toByteArray());
30 reader = (CharColumnReader) specification.readerFor(new DataInputStream(input));
31 }
32
33 /***
34 * Test: leer los strings "abc" y "hola"
35 */
36 public void testRead() throws Exception {
37 String result = (String) reader.read();
38 assertEquals(3, result.length());
39 assertEquals("abc", result);
40
41 result = (String) reader.read();
42 assertEquals(4, result.length());
43 assertEquals("hola", result);
44 }
45 }